<?php
//$id = $_POST['id']; If ($id == "_empty" || $_POST['oper'] =='new') $new = 1;  //echo $id;
if (!$id) $new=1;
if ($_POST['show_occurrance_id']) $fields .= "show_occurrance_id='" . $_POST['show_occurrance_id']."', ";
if ($_POST['schedule_id']) $fields .= "schedule_id='" . $_POST['schedule_id']."', ";
if ($_POST['time_done']) $fields .= "time_done='" . $_POST['time_done']."', ";  

//echo print_r ($_POST);

$fields = rtrim($fields, ', ');

// connect to the database
include "../includes/functions.php";

echo db_connect(); 
 
 if ($_POST['oper'] =='del') {
	$result = mysql_query('DELETE FROM schedules_done WHERE `id` = "'.$id.'"');
	if (!$result) { echo "error deleting record on server side.";}
	exit;	
}
 
 
if ($new) {
	$SQL = "INSERT INTO schedules_done (id, schedule_id, show_occurrance_id, datetime, time_done) VALUES ('','".$_POST['schedule_id']."','".$_POST['show_occurrance_id']."', NOW(), '".$_POST['time_done']."')";//echo $SQL;
} else {
	$SQL = "UPDATE schedules_done SET $fields WHERE id = '$id'"; //echo $SQL;
}

$result = mysql_query( $SQL );

if (!$result) {die("Couldnt execute query.".mysql_error(). $SQL);} else {echo"1";}

?>